<!-- dom 事件学习 -->

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <label for="keywords">Keywords:</label>
    <input type="text" name="" id="keywords"> <!-- autofocus -->
    <script>
        const input = document.querySelector('#keywords');
        //聚焦
        input.addEventListener('focus', function (event) {
            console.log('focus 表单聚焦事件');
        })
        // input.focus();//自动聚焦
        // 按 键盘上的 Tab 键 自动聚焦

        //值改变
        // input.addEventListener('change', function () {
        //     console.log(this.value);
        // })

        //enter 键
        input.addEventListener('keyup', function () {//keydown
            // console.log(this.value);
            if (event.keyCode == 13) {
                console.log('提交表单');
            }
        })

        //及时收集值
        input.addEventListener('input', function () {
            console.log(this.value);
        })
    </script>
</body>

</html>